$('.index').click(function() {
	$('.center').html('');
	$('.nav li').removeClass('active')
	$('.center').load('./' + $(this).attr('index') + '.html');
})

//全局变量，保存学号或教师号
var user = '';
var flag = $.session.get("shenfen");

if(flag == "user") {
	if($.session.get("sno_flag") == 0) {
		user = $.session.get("sno");
	} else {
		user = $.session.get("sno2");
	}
	getUser();
} else if(flag == "teacher") {
	if($.session.get("sno_flag") == 0) {
		user = $.session.get("tno");
		getTeacher();
	} else {
		user = $.session.get("sno2");
		getUser();
	}
} else {
	user = $.session.get("sno2");
	getUser();
}

$(function() {
	var urlPath = getSourceURL() + user + ".jpg";

	isRunUrl(urlPath).then(function(data) {
		$('#img_src_2').attr("src", urlPath);
		console.clear();
	}, function(data) {
		console.clear();
		if(flag == "user") {
			$('#img_src_2').attr("src", "./img/student.jpg");
		} else if(flag == "teacher") {
			$('#img_src_2').attr("src", "./img/teacher.jpg");
		}
	})
})

function getUser() {
	$.ajax({
		xhrFields: {
			withCredentials: true
		},
		url: getFullURL("userInfo"), //请求的url地址
		dataType: "json", //返回格式为json
		async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		data: {
			sno: user
		}, //参数值
		type: "post",
		success: function(data) {
			console.log(data.user)

			$('.student-right').html('')
			$('.student-right').html(`<p>姓&emsp;&emsp;名：&emsp;<span>` + data.user.name + `</span><span class='index' index='cstudent'><a>照片墙></a></span></p>
			    <p>学&emsp;&emsp;校：&emsp;<span>` + data.user.school.sname + `</span></p>
			    <p>专业方向：&emsp;<span>` + data.user.profession + `</span></p>
			    <p>学&emsp;&emsp;号：&emsp;<span>` + data.user.sno + `</span></p>
			    <p>宿&emsp;&emsp;舍：&emsp;<span>` + nullStr(data.user.dorm) + `</span></p>
			    <p>性&emsp;&emsp;别：&emsp;<span>` + nullStr(data.user.sex) + `</span><span class='index' index='studentjianli'><a>查看简历></a></span></p>
			    <p>民&emsp;&emsp;族：&emsp;<span>` + nullStr(data.user.nation) + `</span></p>
			    <p>籍&emsp;&emsp;贯：&emsp;<span>` + nullStr(data.user.place) + `</span></p>
			    <p>生&emsp;&emsp;日：&emsp;<span>` + nullStr(data.born) + `</span></p>
			    <p>年&emsp;&emsp;龄：&emsp;<span>` + nullStr(data.user.age) + `</span></p>
			    <p>身&emsp;&emsp;高：&emsp;<span>` + nullStr(data.user.height) + `</span></p>
			    <p>个人评价：&emsp;<span>` + nullStr(data.user.evaluate) + `</span></p>
			    <p>技能描述：&emsp;<span>` + nullStr(data.user.skill) + `</span></p>
			    <p>求职意向：&emsp;<span>` + nullStr(data.user.intention) + `</span></p>
			    <p>电&emsp;&emsp;话：&emsp;<span>` + nullStr(data.user.phone) + `</span></p>
			    <p>微&emsp;&emsp;信：&emsp;<span>` + nullStr(data.user.wechat) + `</span></p>
			    <p>邮&emsp;&emsp;箱：&emsp;<span>` + nullStr(data.user.email) + `</span></p>
			    <p>企&emsp;&emsp;鹅：&emsp;<span>` + nullStr(data.user.qq) + `</span><span id="information" class='index' index='Modifyinformation'><a>修改资料></a></span></p>`)

			$('.index').click(function() {
				$('.center').html('');
				$('.nav li').removeClass('active')
				$('.center').load('./' + $(this).attr('index') + '.html');
			})

			if($.session.get("sno_flag") == -1) {
				$('#information').css("display", "none");
			}
			//请求成功时处理
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})
}

function getTeacher() {
	$.ajax({
		xhrFields: {
			withCredentials: true
		},
		url: getFullURL("teacher-info"), //请求的url地址
		dataType: "json", //返回格式为json
		async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		data: {
			tno: user
		}, //参数值
		type: "post",
		success: function(data) {
			console.log(data.teacher)

			var zige = '';
			if(data.teacher.type == 1) {
				zige = "毕设老师";
			} else {
				zige = "普通老师";
			}

			$('.student-right').html('')
			$('.student-right').html(`
				<p>账&emsp;&emsp;号：&emsp;<span>` + data.teacher.tno + `</span></p>
				<p>姓&emsp;&emsp;名：&emsp;<span>` + data.teacher.name + `</span></p>
			    <p>资&emsp;&emsp;格：&emsp;<span>` + zige + `</span></p>
			    <p>研究方向：&emsp;<span>` + data.teacher.profession + `</span></p>
			    <p style="padding-bottom: 10px;margin-bottom: 0;border-bottom: 0;">电&emsp;&emsp;话：&emsp;<span>` + nullStr(data.teacher.phone) + `</span></p>
			    <p style="margin-bottom: 20px;">邮&emsp;&emsp;箱：&emsp;<span>` + nullStr(data.teacher.email) + `</span><span id="information" class='index' index='Modifyinformation'><a>修改资料></a></span></p>
			`)

			$('.index').click(function() {
				$('.center').html('');
				$('.nav li').removeClass('active')
				console.log($(this).attr('index'))
				$('.center').load('./' + $(this).attr('index') + '.html');
			})
			//请求成功时处理
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})
}